import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class text{
    public static void main(String[] args) {
        JFrame window=new JFrame("加法计算器");
        window.setSize(300,80);
        /*int w=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
        int h=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
        window.setLocation(w/2-150,h/2-40);*/
        window.setLocationRelativeTo(null);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton btn =new JButton("=");
        JTextField num1=new JTextField(4);
        JTextField num2=new JTextField(4);
        JTextField result=new JTextField(4);
        result.setEditable(false);
        JLabel plus=new JLabel("+");
        /*JButton btn1 =new JButton("1");
        JButton btn2 =new JButton("2");
        JButton btn3 =new JButton("3");
        JButton btn4 =new JButton("4");
        Window.setLayout(new GridLayout(3,2));*/

        window.setLayout(new FlowLayout());
        window.add(num1);
        window.add(plus);
        window.add(num2);
        window.add(btn);
        window.add(result);
        window.setVisible(true);
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int sum = Integer.parseInt(num1.getText()) + Integer.parseInt(num2.getText());
                result.setText(""+sum);
                //result.setText();
                result.setText(Integer.toString(sum));
            }
        });
    }
}